<html>
<head><meta charset="utf-8"><title>Conversion between Read and Iterator&lt;Item = u8&gt; · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Conversion.20between.20Read.20and.20Iterator.3CItem.20.3D.20u8.3E.html">Conversion between Read and Iterator&lt;Item = u8&gt;</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205680750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Conversion%20between%20Read%20and%20Iterator%3CItem%20%3D%20u8%3E/near/205680750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rafael Patronilo <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Conversion.20between.20Read.20and.20Iterator.3CItem.20.3D.20u8.3E.html#205680750">(Aug 01 2020 at 13:08)</a>:</h4>
<p>Hi<br>
<a href="https://discordapp.com/channels/442252698964721669/487245758739906560/738718768905322546">I suggested in Discord:</a></p>
<blockquote>
<p>is there a particular reason why the Read trait isn't implemented for Iterator&lt;Item = u8&gt;? I have found a crate that does an implementation but I feel like this is something that would make sense to be in the standard library</p>
<p>If there is no reason for the lack of this implementation I'd be happy to work on it</p>
</blockquote>
<p><a href="https://discordapp.com/channels/442252698964721669/487245758739906560/738908911058550826">To which scottmcm replied:</a></p>
<blockquote>
<p>Perhaps because there's a bit of an impedence mismatch between item-at-a-time in iterators and the chunkyness that Read tends to prefer.  You could check with libs on zulip for a better answer.</p>
</blockquote>
<p>And while I understand this I feel like it makes sense to be able to have a way to convert between each other. There's a large similarity between both types and a way to pass an <code>Iterator&lt;Item = u8&gt;</code> into a method that requests a <a href="https://doc.rust-lang.org/std/io/trait.Read.html">Read</a> might be useful in many occasions.<br>
Considering that implementing Read for <code>Iterator&lt;Item = u8&gt;</code> wouldn't make sense maybe implementing <code>From&lt;Iterator&lt;Item = u8&gt;&gt;</code> for <code>Read</code> would?</p>



<a name="205683673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Conversion%20between%20Read%20and%20Iterator%3CItem%20%3D%20u8%3E/near/205683673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Conversion.20between.20Read.20and.20Iterator.3CItem.20.3D.20u8.3E.html#205683673">(Aug 01 2020 at 14:25)</a>:</h4>
<p>What are those occasions specifically?</p>



<a name="205683682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Conversion%20between%20Read%20and%20Iterator%3CItem%20%3D%20u8%3E/near/205683682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Conversion.20between.20Read.20and.20Iterator.3CItem.20.3D.20u8.3E.html#205683682">(Aug 01 2020 at 14:25)</a>:</h4>
<p><code>Read</code> is a trait - you can't implement <code>From</code> for it.</p>



<a name="205684446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Conversion%20between%20Read%20and%20Iterator%3CItem%20%3D%20u8%3E/near/205684446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Conversion.20between.20Read.20and.20Iterator.3CItem.20.3D.20u8.3E.html#205684446">(Aug 01 2020 at 14:46)</a>:</h4>
<p>You could make an adapter struct to do this, but that doesn't need to be in the standard library</p>



<a name="205686951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Conversion%20between%20Read%20and%20Iterator%3CItem%20%3D%20u8%3E/near/205686951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rafael Patronilo <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Conversion.20between.20Read.20and.20Iterator.3CItem.20.3D.20u8.3E.html#205686951">(Aug 01 2020 at 15:56)</a>:</h4>
<blockquote>
<p>What are those occasions specifically?</p>
</blockquote>
<p>I was thinking of the generic situation when you have a lib function that returns an object implementing Iterator&lt;Item = u8&gt; and you wanna pass it to a function requesting a Read object (situation which I had yesterday but managed to find another solution).</p>



<a name="205686952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Conversion%20between%20Read%20and%20Iterator%3CItem%20%3D%20u8%3E/near/205686952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rafael Patronilo <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Conversion.20between.20Read.20and.20Iterator.3CItem.20.3D.20u8.3E.html#205686952">(Aug 01 2020 at 15:56)</a>:</h4>
<blockquote>
<p>You could make an adapter struct to do this, but that doesn't need to be in the standard library</p>
</blockquote>
<p>I guess this could indeed be too specific to include in the standard library</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>